package org.onvivals.app.ai.tts;

import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONObject;
import org.onvivals.app.ai.tts.model.aliyun.AliyunTtsService;
import org.onvivals.app.ai.tts.model.chattts.ChatTtsService;
import org.onvivals.app.ai.tts.model.cosyVoice.CosyVoiceTtsService;
import org.onvivals.app.ai.tts.model.minimax.MinimaxTtsService;
import org.onvivals.app.ai.tts.model.reecho.ReechoTtsService;
import org.onvivals.app.ai.tts.model.volcengine.VolcengineTtsService;
import org.onvivals.common.constant.Constant;
import org.onvivals.module.pms.entity.PmsRole;
import org.onvivals.module.pms.entity.PmsTtsConfig;
import org.onvivals.module.pms.service.IPmsTtsConfigService;

public class TTSFactory {

	private static IPmsTtsConfigService ttsConfigService;

	static {
		TTSFactory.ttsConfigService = SpringUtil.getBean(IPmsTtsConfigService.class);
	}

	public static AbstractTtsService build(PmsRole roles) {
		PmsTtsConfig pmsTtsConfig = ttsConfigService.getById(roles.getTtsId());
		JSONObject role = pmsTtsConfig.getTtsConfig();
		String ttsType = pmsTtsConfig.getTtsType();
		if (ttsType.equals(Constant.ttsService.VOLCENGINE.getValue())) {
			return new VolcengineTtsService(role);
		}if (ttsType.equals(Constant.ttsService.ALIYUN.getValue())) {
			return new AliyunTtsService(role);
		}if (ttsType.equals(Constant.ttsService.MINIMAX.getValue())) {
			return new MinimaxTtsService(role);
		}if (ttsType.equals(Constant.ttsService.REECHO.getValue())) {
			return new ReechoTtsService(role);
		}if  (ttsType.equals(Constant.ttsService.CHATTTS.getValue())) {
			return new ChatTtsService(role);
		}if (ttsType.contains(Constant.ttsService.COSYVOICE.getValue())) {
			return new CosyVoiceTtsService(role,roles);
		}
		return null;
	}
}
